/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package queenb.web.controller;

import java.util.ArrayList;
import java.util.List;
import javax.faces.event.ActionEvent;
import javax.faces.event.ValueChangeEvent;
import queenb.net.entitybean.C350;
import queenb.web.store.C350Store;
import queenb.web.util.SessionProvider;
import queenb.web.util.Util;

/**
 *
 * @author Nguyen Hung
 */
public class C350Controller extends QueenbController {

    private int PC350;
    private int CN351;
    private String pvCV352;
    private String pvCV353;
    private int FC425;
    private C350Store c350Store;
    private List<C350> listC350 = new ArrayList<C350>();

    public C350Controller() {
        c350Store = new C350Store();
        Object action = getRequest().getParameter("action");
        if (action != null) {
            if (action.equals("getListC350")) {
                Object objFC425 = getRequest().getParameter("fc425");
                if (objFC425 != null) {
                    FC425 = Util.parseInt(objFC425);
                }
            } else if (action.equals("editC350")) {
                Object objPC350 = getRequest().getParameter("pc350");
                if (objPC350 != null) {
                    PC350 = Util.parseInt(objPC350);

                    List<C350> list = c350Store.ccurpks_listoftabc350(getLogin().getModule(), getLogin().getCompanyNo(), 0, getLogin().getUserName());
                    if (list != null) {
                        for (int i = 0; i < list.size(); i++) {
                            if (list.get(i).getPc350() == PC350) {
                                FC425 = list.get(i).getFc425();
                                pvCV352 = list.get(i).getCv352();
                                pvCV353 = list.get(i).getCv353();
                                CN351 = list.get(i).getCn351();
                            }
                        }
                    }
                }
            }else if(action.equals("deleteC350")){
                 Object objPC350 = getRequest().getParameter("pc350");
                if (objPC350 != null) {
                    PC350 = Util.parseInt(objPC350);
                    SessionProvider.setSessionMapValue("IDC350DELETE", PC350);
                }
            }
        }
    }
// delete
    public void stdc_tools_stornotabc350() {
        try {
            int count = c350Store.stdc_tools_stornotabc350(Util.parseInt(SessionProvider.getSessionMapValue("IDC350DELETE")), getLogin().getUserName());
            if (count != 0) {
                //   showGlobalReport(true, getResourceString("success"));
                System.out.println("-----THAM SO----");
            } else {
                //   showGlobalReport(true, getResourceString("error"));
            }

            //           sendRedirectUrlTab("setting.jsp?tab=header31&llinkC425=" + Util.convertMD5(getRequest().getRequestURI()));
        } catch (Exception e) {
        }
    }
    public void stdc_tools_inserttabc425() {
        try {
          
            int count = c350Store.stdc_tools_inserttabc350(PC350, getLogin().getModule(), getLogin().getCompanyNo(), FC425, CN351, pvCV352, pvCV353, getLogin().getUserName());
            if (count != 0) {
                //   showGlobalReport(true, getResourceString("success"));
                System.out.println("-----THAM SO----");
            } else {
                //   showGlobalReport(true, getResourceString("error"));
            }

            //           sendRedirectUrlTab("setting.jsp?tab=header31&llinkC425=" + Util.convertMD5(getRequest().getRequestURI()));
        } catch (Exception e) {
        }
    }
// Onchange 

    public void actionSearch(ActionEvent ac) {
        try {
            SessionProvider.setSessionMapValue("IDFC425ONCHANGEE", FC425);
        } catch (Exception e) {
        }

    }

    public void actionSearchpopup(ValueChangeEvent event) {
        try {
            FC425 = Integer.parseInt(event.getNewValue().toString());
            SessionProvider.setSessionMapValue("IDFC425ONCHANGEE", FC425);
        } catch (Exception e) {
        }


    }

    public void stdc_tools_inserttabc4251() {
        try {
            sendRedirectUrlTab("setting.jsp?tab=header31&llinkC425=" + Util.convertMD5(getRequest().getRequestURI()));
        } catch (Exception e) {
        }
    }

    /**
     * @return the PC350
     */
    public int getPC350() {
        return PC350;
    }

    /**
     * @param PC350 the PC350 to set
     */
    public void setPC350(int PC350) {
        this.PC350 = PC350;
    }

    /**
     * @return the CN351
     */
    public int getCN351() {
        return CN351;
    }

    /**
     * @param CN351 the CN351 to set
     */
    public void setCN351(int CN351) {
        this.CN351 = CN351;
    }

    /**
     * @return the pvCV352
     */
    public String getPvCV352() {
        return pvCV352;
    }

    /**
     * @param pvCV352 the pvCV352 to set
     */
    public void setPvCV352(String pvCV352) {
        this.pvCV352 = pvCV352;
    }

    /**
     * @return the pvCV353
     */
    public String getPvCV353() {
        return pvCV353;
    }

    /**
     * @param pvCV353 the pvCV353 to set
     */
    public void setPvCV353(String pvCV353) {
        this.pvCV353 = pvCV353;
    }

    /**
     * @return the FC425
     */
    public int getFC425() {
        if (SessionProvider.getSessionMapValue("IDFC425ONCHANGEE") != null) {
            FC425 = Util.parseInt(SessionProvider.getSessionMapValue("IDFC425ONCHANGEE"));
        }
        return FC425;
    }

    /**
     * @param FC425 the FC425 to set
     */
    public void setFC425(int FC425) {
        this.FC425 = FC425;
    }

    /**
     * @return the c350Store
     */
    public C350Store getC350Store() {
        return c350Store;
    }

    /**
     * @param c350Store the c350Store to set
     */
    public void setC350Store(C350Store c350Store) {
        this.c350Store = c350Store;
    }

    /**
     * @return the listC350
     */
    public List<C350> getListC350() {
        try {
            System.out.println("--------------------FC425-------" + FC425);
            if (SessionProvider.getSessionMapValue("IDFC425ONCHANGEE") != null) {
                FC425 = Util.parseInt(SessionProvider.getSessionMapValue("IDFC425ONCHANGEE"));
            }
            listC350 = c350Store.ccurpks_listoftabc350(getLogin().getModule(), getLogin().getCompanyNo(), FC425, getLogin().getUserName());
            return listC350;
        } catch (Exception e) {
            return null;
        }

    }

    /**
     * @param listC350 the listC350 to set
     */
    public void setListC350(List<C350> listC350) {
        this.listC350 = listC350;
    }
}
